# coding=utf8
from app.extensions import db
from app.modules.common.utils import JsonEncoder


class ProdSchemaDefine(db.Model, JsonEncoder):
    __tablename__ = "prod_schema_define"
    id = db.Column(db.Integer, primary_key = True)
    table_schema = db.Column(db.String)
    is_ignore = db.Column(db.String)
    schema_owner = db.Column(db.String)
    remark = db.Column(db.String)

    def __init__(self, id = None, table_schema = None, is_ignore = None, schema_owner = None, remark = None):
        self.id = id
        self.table_schema = table_schema
        self.is_ignore = is_ignore
        self.schema_owner = schema_owner
        self.remark = remark

    def to_dict(self):
        return {
            'id': self.id,
            'table_schema': self.table_schema,
            'is_ignore': self.is_ignore,
            'schema_owner': self.schema_owner,
            'remark': self.remark,
        }


class ProdTableCheckRows(db.Model, JsonEncoder):
    __tablename__ = "prod_table_check_rows"
    id = db.Column(db.Integer, primary_key = True)
    table_schema = db.Column(db.String)
    table_name = db.Column(db.String)
    this_rows = db.Column(db.Integer)
    checked_rows = db.Column(db.Integer)
    checked_date = db.Column(db.DateTime)
    checkedby = db.Column(db.String)
    remark = db.Column(db.String)

    def __init__(self, id = None, table_schema = None, table_name = None, this_rows = None, checked_rows = None,
                 checked_date = None, checkedby = None, remark = None):
        self.id = id
        self.table_schema = table_schema
        self.table_name = table_name
        self.this_rows = this_rows
        self.checked_rows = checked_rows
        self.checked_date = checked_date
        self.checkedby = checkedby
        self.remark = remark

    def to_dict(self):
        return {
            'id': self.id,
            'table_schema': self.table_schema,
            'table_name': self.table_name,
            'this_rows': self.this_rows,
            'checked_rows': self.checked_rows,
            'checked_date': self.checked_date.strftime('%Y-%m-%d %H:%M:%S') if self.checked_date else None,
            'checkedby': self.checkedby,
            'remark': self.remark,
        }


class ProdTableClean(db.Model, JsonEncoder):
    __tablename__ = "prod_table_clean"
    id = db.Column(db.Integer, primary_key = True)
    table_schema = db.Column(db.String)
    table_name = db.Column(db.String)
    script = db.Column(db.String)
    sort = db.Column(db.Integer)
    remark = db.Column(db.String)
    is_active = db.Column(db.String)
    created = db.Column(db.DateTime)
    createdby = db.Column(db.String)
    updated = db.Column(db.DateTime)
    updatedby = db.Column(db.String)

    def __init__(self, id = None, table_schema = None, table_name = None, script = None, remark = None,
                 is_active = None, created = None, createdby = None, updated = None, updatedby = None, sort = None):
        self.id = id
        self.table_schema = table_schema
        self.table_name = table_name
        self.script = script
        self.remark = remark
        self.is_active = is_active
        self.created = created
        self.createdby = createdby
        self.updated = updated
        self.updatedby = updatedby
        self.sort = sort

    def to_dict(self):
        return {
            'id': self.id,
            'table_schema': self.table_schema,
            'table_name': self.table_name,
            'sort': self.sort,
            'script': self.script,
            'remark': self.remark,
            'is_active': self.is_active,
            'createdby': self.createdby,
            'created': self.created.strftime('%Y-%m-%d %H:%M:%S') if self.created else None,
            'updatedby': self.updatedby,
            'updated': self.updated.strftime('%Y-%m-%d %H:%M:%S') if self.updated else None,
        }


class ProdTableDefine(db.Model, JsonEncoder):
    __tablename__ = "prod_table_define"
    id = db.Column(db.Integer, primary_key = True)
    table_schema = db.Column(db.String)
    table_name = db.Column(db.String)
    engine = db.Column(db.String)
    row_format = db.Column(db.String)
    table_rows = db.Column(db.Integer)
    data_length = db.Column(db.Integer)
    index_length = db.Column(db.Integer)
    auto_increment = db.Column(db.Integer)
    create_time = db.Column(db.DateTime)
    table_collation = db.Column(db.String)
    table_comment = db.Column(db.String)
    updated = db.Column(db.DateTime)
    is_ignore = db.Column(db.String)
    is_check_rows = db.Column(db.String)
    is_need_clean = db.Column(db.String)
    manager = db.Column(db.String)
    purpose = db.Column(db.String)

    def __init__(self, id = None, table_schema = None, table_name = None, engine = None, row_format = None,
                 table_rows = None, data_length = None, index_length = None, auto_increment = None, create_time = None,
                 table_collation = None, table_comment = None, updated = None, is_ignore = None, is_check_rows = None,
                 is_need_clean = None, manager = None, purpose = None):
        self.id = id
        self.table_schema = table_schema
        self.table_name = table_name
        self.engine = engine
        self.row_format = row_format
        self.table_rows = table_rows
        self.data_length = data_length
        self.index_length = index_length
        self.auto_increment = auto_increment
        self.create_time = create_time
        self.table_collation = table_collation
        self.table_comment = table_comment
        self.updated = updated
        self.is_ignore = is_ignore
        self.is_check_rows = is_check_rows
        self.is_need_clean = is_need_clean
        self.manager = manager
        self.purpose = purpose

    def to_dict(self):
        return {
            'id': self.id,
            'table_schema': self.table_schema,
            'create_time': self.create_time.strftime('%Y-%m-%d %H:%M:%S') if self.create_time else None,
            'updated': self.updated.strftime('%Y-%m-%d %H:%M:%S') if self.updated else None,
            'table_name': self.table_name,
            'table_collation': self.table_collation,
            'table_comment': self.table_comment,
            'engine': self.engine,
            'row_format': self.row_format,
            'table_rows': self.table_rows,
            'data_length': self.data_length,
            'index_length': self.index_length,
            'auto_increment': self.auto_increment,
            'is_ignore': self.is_ignore,
            'is_check_rows': self.is_check_rows,
            'is_need_clean': self.is_need_clean,
            'manager': self.manager,
            'purpose': self.purpose,
        }


class ProdTableExport(db.Model, JsonEncoder):
    __tablename__ = "prod_table_export"
    id = db.Column(db.Integer, primary_key = True)
    table_schema = db.Column(db.String)
    table_name = db.Column(db.String)
    env_type = db.Column(db.String)
    script = db.Column(db.String)
    remark = db.Column(db.String)
    created = db.Column(db.DateTime)
    createdby = db.Column(db.String)
    updated = db.Column(db.DateTime)
    updatedby = db.Column(db.String)

    def __init__(self, id = None, table_schema = None, table_name = None, env_type = None, script = None, remark = None,
                 created = None, createdby = None, updated = None, updatedby = None):
        self.id = id
        self.table_schema = table_schema
        self.table_name = table_name
        self.env_type = env_type
        self.script = script
        self.remark = remark
        self.created = created
        self.createdby = createdby
        self.updated = updated
        self.updatedby = updatedby

    def to_dict(self):
        return {
            'id': self.id,
            'table_schema': self.table_schema,
            'created': self.created.strftime('%Y-%m-%d %H:%M:%S') if self.created else None,
            'updated': self.updated.strftime('%Y-%m-%d %H:%M:%S') if self.updated else None,
            'table_name': self.table_name,
            'env_type': self.env_type,
            'script': self.script,
            'remark': self.remark,
            'createdby': self.createdby,
            'updatedby': self.updatedby,
        }


class ProdTableInit(db.Model, JsonEncoder):
    __tablename__ = "prod_table_init"
    id = db.Column(db.Integer, primary_key = True)
    table_schema = db.Column(db.String)
    table_schema_instance = db.Column(db.String)
    env_type = db.Column(db.String)
    script = db.Column(db.String)
    remark = db.Column(db.String)
    is_active = db.Column(db.String)
    created = db.Column(db.DateTime)
    createdby = db.Column(db.String)
    updated = db.Column(db.DateTime)
    updatedby = db.Column(db.String)

    def __init__(self, id = None, table_schema = None, table_schema_instance = None, env_type = None, script = None,
                 remark = None, is_active = None, created = None, createdby = None, updated = None, updatedby = None):
        self.id = id
        self.table_schema = table_schema
        self.table_schema_instance = table_schema_instance
        self.env_type = env_type
        self.script = script
        self.remark = remark
        self.is_active = is_active
        self.created = created
        self.createdby = createdby
        self.updated = updated
        self.updatedby = updatedby

    def to_dict(self):
        return {
            'id': self.id,
            'table_schema': self.table_schema,
            'created': self.created.strftime('%Y-%m-%d %H:%M:%S') if self.created else None,
            'updated': self.updated.strftime('%Y-%m-%d %H:%M:%S') if self.updated else None,
            'table_name': self.table_name,
            'env_type': self.env_type,
            'script': self.script,
            'is_active': self.is_active,
            'remark': self.remark,
            'createdby': self.createdby,
            'updatedby': self.updatedby,
        }
